package course13;

public class Mistake4 {
    public static void test1(int x) throws ArrayIndexOutOfBoundsException, Exception {
        System.out.println(x);
        if (x == 0) {
            System.out.println("没有异常");
        }
        //数组越界处理
        else if (x == 1) {
           try {
               int[] a = new int[3];
               a[3] = 5;
           }catch (ArrayIndexOutOfBoundsException e){
               System.out.println("出现错误！"+e);
           }
        }
        //算数异常
        else if (x==2){
            try {
                int i=0;
                int j=5/0;
            }catch (Exception e){
                System.out.println("出现错误！"+e);
            }

    }
    }

    public static void main(String[] args) {
        try {
            test1(2);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
